home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / xw2.000 / xw2 / xw / xbmfx / xbmfx.c next >
Encoding:
C/C++ Source or Header  |  1995-02-02  |  5.8 KB  |  228 lines

  1.  
  2. #include "stdlib.h"
  3. #include "stdio.h"
  4. #include "string.h"
  5.  
  6. #include "xbmfx.h"
  7.  
  8. /*{{{  Pack Text String*/
  9. #define XbWMFX_PckTLen 250
  10. char XbWMFX_PTS[XbWMFX_PckTLen];
  11. char *XbWMFX_PckTxt(char *str){
  12.   int cc,ll;
  13.   cc = 0;
  14.   while((str[cc] == ' ') & (strlen(str) > cc)) {
  15.     cc++;
  16.     }
  17.   ll = 0;
  18.   while((ll< strlen((char *)str))&(ll<XbWMFX_PckTLen)){
  19.     XbWMFX_PTS[ll] = str[cc+ll];
  20.     ll++;
  21.     }
  22.   if (strlen(str) >= XbWMFX_PckTLen) {
  23.     XbWMFX_PTS[XbWMFX_PckTLen-1] = 0;
  24.     }
  25.   else {
  26.     XbWMFX_PTS[strlen(str)] = 0;
  27.     }
  28.   while((XbWMFX_PTS[strlen(XbWMFX_PTS)-1] == ' ') & (strlen(XbWMFX_PTS) > 0)) {
  29.     XbWMFX_PTS[strlen((char *)XbWMFX_PTS)-1] = 0;
  30.     }
  31.   return(XbWMFX_PTS);
  32.   }
  33. /*}}}  */
  34. /*{{{  char *XbWMFX_MyStrUpr(char*sstr){*/
  35. char *XbWMFX_MyStrUpr(char*sstr){
  36.   int ll;
  37.   for (ll=0;sstr[ll]!=0;ll++){
  38.     sstr[ll]&=0xDF;
  39.     }
  40.   return(sstr);
  41.   }
  42. /*}}}  */
  43. /*{{{  int XbWMFX_MyStrICmp(char *sstra,char*sstrb){*/
  44. int XbWMFX_MyStrICmp(char *sstra,char*sstrb){
  45.   char sstr1[200],sstr2[200];
  46.   strcpy(sstr1,sstra);
  47.   strcpy(sstr2,sstrb);
  48.   XbWMFX_MyStrUpr(sstr1);XbWMFX_MyStrUpr(sstr2);
  49.   return(strcmp(sstr1,sstr2));
  50.   }
  51. /*}}}  */
  52. /*{{{  #define XbWMFX_MaxNames 5*/
  53. #define XbWMFX_MaxNames 5
  54. FILE
  55.   *XbWMFX_File;
  56. char
  57.   XbWMFX_FilName[80],
  58.   XbWMFX_Filezeile[255];
  59. int
  60.   XbWMFX_FilZlNr,
  61.   XbWMFX_AktName,
  62.   XbWMFX_ReadErr = 0;
  63. int
  64.   XbWMFX_Debug = 0;
  65. char
  66.   XbWMFX_FStrNames[XbWMFX_MaxNames][200];
  67. /*}}}  */
  68. char *XbWMFX_GetLine(void){
  69.   XbWMFX_FilZlNr++;
  70.   return(fgets(XbWMFX_Filezeile,253,XbWMFX_File));
  71.   }
  72. int XbWMFX_ReadSet( char *filename, char *dataset){
  73.   /*{{{  */
  74.   int ll;
  75.   unsigned char ende;
  76.   int found;
  77.   char namestr[255];
  78.   XbWMFX_FilZlNr = 0;
  79.   for (ll=0;ll<XbWMFX_MaxNames;ll++){
  80.     strcpy(XbWMFX_FStrNames[ll],"\0");
  81.     }
  82.   strcpy(XbWMFX_FilName,filename);
  83.   found = 0;
  84.   XbWMFX_ReadErr = 0;
  85.   if ((XbWMFX_File = fopen(filename,"r")) == NULL) {
  86.     return(1);
  87.     }
  88.   ende = 0;
  89.   while (!ende) {
  90.     if (XbWMFX_GetLine() == NULL) {
  91.       ende = 1;}
  92.     else {
  93.       if (strstr(XbWMFX_Filezeile,"\\VarStructContents{") != NULL) {
  94.         if (XbWMFX_GetLine() == NULL) {
  95.           return(1);
  96.           }
  97.         else {
  98.           if (
  99.                 (strstr(XbWMFX_Filezeile,"{") != NULL) &
  100.                 (strstr(XbWMFX_Filezeile,"}") != NULL)
  101.              ) {
  102.             strncpy(namestr,strstr(XbWMFX_Filezeile,"{")+1,250);
  103.             strcpy(strstr(namestr,"}"),"\0");;
  104.             if ((strcmp(namestr,dataset)==0)|(strcmp(dataset,"*")==0)) {
  105.               ende = 1;
  106.               found = 1;
  107.               }
  108.             else {
  109.               if (XbWMFX_AktName < XbWMFX_MaxNames) {
  110.                 strcpy(XbWMFX_FStrNames[XbWMFX_AktName],namestr);
  111.                 }
  112.               XbWMFX_AktName++;
  113.               }
  114.             }
  115.           }
  116.         }
  117.       }
  118.     }
  119.   if (!found){ return(1); }
  120.   return(0);
  121.   }
  122.   /*}}}  */
  123. int XbWMFX_GetInteger(int *variable){
  124.   /*{{{  */
  125.   char sstr[255];
  126.   XbWMFX_GetLine();
  127.   while (*(char *)XbWMFX_PckTxt(XbWMFX_Filezeile) == '%') {
  128.     if (feof(XbWMFX_File)){ return(1);}
  129.     XbWMFX_GetLine();
  130.     }
  131.   if (*(char *)XbWMFX_PckTxt(XbWMFX_Filezeile) != 'i') { return(1); }
  132.   strncpy(sstr,strstr(XbWMFX_Filezeile,"i")+1,255);
  133.   *(char *)strstr(sstr,",") = 0;
  134.   *variable = atoi((char *)XbWMFX_PckTxt(sstr));
  135.   return(0);
  136.   }
  137.   /*}}}  */
  138. int XbWMFX_GetShort(short *variable){
  139.   /*{{{  */
  140.   char sstr[255];
  141.   XbWMFX_GetLine();
  142.   while (*(char *)XbWMFX_PckTxt(XbWMFX_Filezeile) == '%') {
  143.     if (feof(XbWMFX_File)){ return(1);}
  144.     XbWMFX_GetLine();
  145.     }
  146.   if (*(char *)XbWMFX_PckTxt(XbWMFX_Filezeile) != 'i') { return(1); }
  147.   strncpy(sstr,strstr(XbWMFX_Filezeile,"i")+1,255);
  148.   if (strstr(sstr,",") != NULL){
  149.     *(char *)strstr(sstr,",") = 0;
  150.     }
  151.   *variable = (short)(atoi((char *)XbWMFX_PckTxt(sstr)));
  152.   return(0);
  153.   }
  154.   /*}}}  */
  155. int XbWMFX_GetDouble(double *variable){
  156.   /*{{{  */
  157.   char sstr[255];
  158.   XbWMFX_GetLine();
  159.   while (*(char *)XbWMFX_PckTxt(XbWMFX_Filezeile) == '%') {
  160.     if (feof(XbWMFX_File)){ return(1);}
  161.     XbWMFX_GetLine();
  162.     }
  163.   if (*((char *)XbWMFX_PckTxt(XbWMFX_Filezeile)) != '{') { return(1); }
  164.   strncpy(sstr,strstr(XbWMFX_Filezeile,"{")+1,255);
  165.   if (strstr(sstr,"}") != NULL) {
  166.     *(char *)strstr(sstr,"}") = 0;
  167.     }
  168.   else {return(1);}
  169.   *variable = atof((char *)XbWMFX_PckTxt(sstr));
  170.   return(0);
  171.   }
  172.   /*}}}  */
  173. int XbWMFX_GetString(char *variable){
  174.   /*{{{  */
  175.   char sstr[255];
  176.   
  177.   XbWMFX_GetLine();
  178.   while (*(char *)XbWMFX_PckTxt(XbWMFX_Filezeile) == '%') {
  179.     if (feof(XbWMFX_File)){ return(1);}
  180.     XbWMFX_GetLine();
  181.     }
  182.   if (*((char *)XbWMFX_PckTxt(XbWMFX_Filezeile)) != '{') { return(1); }
  183.   strncpy(sstr,strstr(XbWMFX_Filezeile,"{")+1,253);
  184.   sstr[253]=0;
  185.   if (strstr(sstr,"}") != NULL) {
  186.     *(char *)strstr(sstr,"}") = 0;
  187.     }
  188.   else {return(1);}
  189.   strcpy(sstr,(char *)XbWMFX_PckTxt(sstr));
  190.   strcpy(variable,sstr);
  191.   return(0);
  192.   }
  193.   /*}}}  */
  194. int XbWMFX_WriteSet( char *filename, char *dataset, char *mode){
  195.   /*{{{  */
  196.   XbWMFX_File = fopen(filename,mode);
  197.   if (XbWMFX_File == NULL) { return(1); }
  198.   if (mode[0]=='a'){
  199.     fseek(XbWMFX_File,0,SEEK_END);
  200.     }
  201.   fputs("\\VarStructContents{\n",XbWMFX_File);
  202.   fputs(" {",XbWMFX_File);
  203.   fputs(dataset,XbWMFX_File);
  204.   fputs("}}\n",XbWMFX_File);
  205.   return(0);
  206.   }
  207.   /*}}}  */
  208. void XbWMFX_PutShort(short *variable,  char *comment){
  209.   fprintf(XbWMFX_File," i%d, %s\n",(int)*variable, comment);}
  210. void XbWMFX_PutInteger(int *variable,  char *comment){
  211.   fprintf(XbWMFX_File," i%d, %s\n",*variable, comment);}
  212. void XbWMFX_PutDouble(double *variable,  char *comment){
  213.   fprintf(XbWMFX_File," {%25.12f}, %s\n",*variable, comment);}
  214. void XbWMFX_PutString(char *variable, char *comment){
  215.   if (variable == NULL) {
  216.     fprintf(XbWMFX_File," {(null)}, %s\n", comment);
  217.     }
  218.   else {
  219.     fprintf(XbWMFX_File," {%s}, %s\n",variable, comment);
  220.     }
  221.   }
  222. void XbWMFX_WriteEnd(void){
  223.   fputs("\\EndOfVarStructure;\n",XbWMFX_File);}
  224. void XbWMFX_CloseSet(void){
  225.   fclose(XbWMFX_File);}
  226.  
  227.  
  228.